using UnityEngine;
using UnityEngine.UI;


public class Prefab_StoreItem : MonoBehaviour
{
    public Button Btn_Buy;
    public Button Btn_Sell;
    public Image Img_Icon;
    public Text Lab_Name;
    public Text Lab_Desc;
    public Text Lab_Price;
    public Text Lab_curCount;
    public Item ItemCfg;
    public ItemData ItemData;
    public int BuyOrSellCount;



    // Start is called before the first frame update
    void Start()
    {
    }


    public void Init(Item cfg)
    {
        Btn_Buy = gameObject.transform.GetChild(0).gameObject.GetComponent<UnityEngine.UI.Button>();
        Btn_Sell = gameObject.transform.GetChild(1).gameObject.GetComponent<UnityEngine.UI.Button>();
        Img_Icon = gameObject.transform.GetChild(2).GetComponent<UnityEngine.UI.Image>();
        Lab_Name = gameObject.transform.GetChild(3).GetComponent<Text>();
        Lab_Desc = gameObject.transform.GetChild(4).GetComponent<Text>();
        Lab_Price = gameObject.transform.GetChild(5).GetComponent<Text>();
        Lab_curCount = gameObject.transform.GetChild(6).GetComponent<Text>();
        ItemData = new ItemData(cfg, 1);
        BuyOrSellCount = 5;
        Lab_Name.text = cfg.Name;
        Lab_Price.text = cfg.Price * Logic.CalculateRate(cfg.Event) + "";
        Lab_Desc.text = cfg.Desc;
        ItemCfg = cfg;
        Btn_Buy.onClick.AddListener(() => { Logic.BuyItem(this, ItemData); });
        Btn_Sell.onClick.AddListener(() => { Logic.SellItem(this, ItemData); });
    }

    // Update is called once per frame
    void Update()
    {

    }
    //还差一个选择购买或出售数量的，做成可以点击加减，也可以点击文字框输入，改成点击购买或者出售，弹出二次确认窗口，在那个面板里选择数量；

    void OnDestroy()
    {
        Btn_Buy.onClick.RemoveListener(() => { Logic.BuyItem(this, ItemData); });
        Btn_Sell.onClick.RemoveListener(() => { Logic.SellItem(this, ItemData); });
    }
}
